<!DOCTYPE html>
<html>

<head>
	<title>小水滴</title>
	<meta name="keywords"  />
	<meta name="description" content="" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
	<!-- Custom Theme files 1280*559-->
  	<link href="/static/js/layui/css/layui.css" rel="stylesheet">
	<link href="/static/js/layui/css/form.css" rel="stylesheet">
	<!-- //Custom Theme files -->
	<!-- 青、赤、黄、白、黑 -->
  	<script src="/static/js/layui/layui.js"></script>
  	<script src="/static/js/common.js"></script>
</head>

<body class="body-page">
	<div class="search layui-form" lay-filter="search">
		<div class="form-table">
			<div class="form-row">
				<div class="form-cell">
					<label>名称</label>
				</div>
				<div class="form-cell">
					<input type="text" name="name" lay-affix="clear" lay-verify="required" lay-vertype="tips" placeholder="请输入名称" autocomplete="off" class="layui-input">
				</div>
				<div class="form-cell">
					<button class="layui-btn layui-btn-sm" id="search">搜索</button>
					<button class="layui-btn layui-btn-sm" id="create">新增</button>
				</div>
			</div>
		</div>
	</div>
	<div class="grid">
		<table class="layui-hide" id="table" lay-filter="table"></table>
	</div>
</body>
<script>
	var tableId = 'table'+c.uuid();
	var editArea = ['600px', '500px'];

	$(function(){
		c.table({
			elem: '#table',
			url: '/sysApp/page',
			id:tableId,
			height: 'full',
			cellMinWidth: 80,
			page: true,
			cols: [[
				{field:'name',title: '标品名称',width:180},
				{field:'remarks',title: '标品简介',width:200},
				{field:'cp',title: '产品',width:120},
				{field:'yf',title: '研发',width:120},
				{field:'cs',title: '测试',width:120},
				{field:'op',title: '操作',width:180,templet:function(row){
					var edit = '<a href="javascript:editRow(&apos;'+row.id+'&apos;);" class="bluea">编辑</a>';
					var del = '<a href="javascript:deleteRow(&apos;'+row.id+'&apos;);" class="reda">删除</a>';
					return edit+c.opSpace()+del;
				}}
			]],
			error: function(res, msg){
				console.log(res, msg)
			}
		});

		$('#create').click(function(){
			c.window({
				area: editArea,
				content:'/html/sysapp_add.html'
			});
		});

		$('#search').click(function(){
			reloadTable({where:c.putPrefix(form.val('search'),'sysApp.')});
		});
	});

	function reloadTable(queryParams){
		queryParams = queryParams ? queryParams : {};
		table.reloadData(tableId,queryParams,true);
	}

	function editRow(id){
		c.window({
			area: editArea,
			content:'/html/sysapp_add.html?id='+id
		});
	}

	function deleteRow(id){
    	layer.confirm('确定要删除吗？', {icon: 3, title:'提示'}, function(index){
			c.request('sysApp/delete',{id:id},function(resp){
				if( resp.code == 200 ){
					c.message('删除成功');
				}else{
					c.message(resp.message);
				}
				reloadTable();
			});
			layer.close(index);
		});
	}

	
</script>
</html>